package com.songdehuai.supermarket;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.songdehuai.supermarket.adapter.ViewPagerAdapter;
import com.songdehuai.supermarket.base.BaseAcitivity;
import com.songdehuai.supermarket.fragment.EvaluationFragment;
import com.songdehuai.supermarket.fragment.ShopListFragment;
import com.songdehuai.supermarket.presenter.SuperMarketPresenter;
import com.songdehuai.supermarket.presenter.imp.SuperMarketPresenterImp;
import com.songdehuai.supermarket.result.Result;
import com.songdehuai.supermarket.supermarket.entity.SuperMarket;
import com.songdehuai.supermarket.sync.SuperMarketSync;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

public class SuperMarketActivity extends BaseAcitivity implements SuperMarketSync {

    @ViewInject(R.id.main_vp)
    private ViewPager mainVp;
    @ViewInject(R.id.main_tab)
    private TabLayout mainTabLayout;
    //商品
    private ShopListFragment shopListFragment;
    //评价
    private EvaluationFragment evaluationFragment;

    private String superMarketId;

    SuperMarketPresenter presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supermarket);
        x.view().inject(this);
        initViews();
    }

    private void initViews() {
        superMarketId = getIntent().getStringExtra("ID");
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        shopListFragment = new ShopListFragment();
        evaluationFragment = new EvaluationFragment();
        viewPagerAdapter.addFrag(shopListFragment, "商品");
        viewPagerAdapter.addFrag(evaluationFragment, "评价");
        mainVp.setAdapter(viewPagerAdapter);
        mainTabLayout.setupWithViewPager(mainVp);

        presenter = new SuperMarketPresenterImp(SuperMarketActivity.this, this);
        presenter.getSuperMarket(false,superMarketId);
    }

    @Override
    public void superMarketSuccess(Result<SuperMarket> superMarketResult) {
        shopListFragment.initMenu(superMarketResult.getResult().getProduct());
    }
}
